package parking.manager;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

public class Slot {
    
    private int _orderNumber;
    private SlotStatus _status;
    private Graphics2D _graphics;
    private Vehicle _vehicle;
    
    public Slot(int orderNumber, Graphics g)
    {
        _status = SlotStatus.Free;
        _orderNumber = orderNumber;
        _graphics = (Graphics2D)g;
    }
    
    public SlotStatus GetSlotStatus()
    {
        return _status;
    }
     
    public void UpdateSlotStatus(SlotStatus slotStatus)
    {
        _status = slotStatus;
    }
    
    public int GetOrderNumber()
    {
        return _orderNumber;
    }
    
    public void ParkVehicle(Vehicle vehicle)
    {
        _vehicle = vehicle;
        UpdateSlotStatus(SlotStatus.Occupied);
    }
    
    public Vehicle GetVehicle()
    {
        return _vehicle;
    }
    
    public void ReleaseSlot()
    {
        _vehicle = null;
        UpdateSlotStatus(SlotStatus.Free);
    }
    
    public void Draw()
    {
        if (_status == SlotStatus.Free) {
            _graphics.setColor(Color.green);
        } else {
            _graphics.setColor(Color.red);
        }
        _graphics.setStroke(new BasicStroke(2));
        
        int x = (_orderNumber % 5) * 70 + 10;
        int y = 10 + (80 * (_orderNumber / 5));
        int width = 60;
        int height = 70;
        _graphics.drawRect(x, y, width, height);
        _graphics.drawLine(x, y, x + width, y + height);
        _graphics.drawLine(x + width, y, x, y + height);
    }
}
